package com.loto.insurance.mis.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.loto.insurance.mis.web.authority.INSAuthority;
import com.loto.insurance.mis.web.enumeration.IsActiveEnum;
import com.loto.insurance.mis.web.enumeration.CustTypeEnum;
import com.loto.insurance.mis.web.enumeration.MenuEnum;
import com.loto.insurance.mis.web.service.SupInfoService;

@Controller
public class SupController {
  @Autowired
  SupInfoService supInfoService;

  @INSAuthority(authorityMenu = MenuEnum.SUPPLIER_LIST)
  @RequestMapping(value = "/supplier/list", method = RequestMethod.GET)
  public String supplierlist(Model model) {
	model.addAttribute("subId", MenuEnum.SUPPLIER_LIST.getIndex());
	return "supplier/supplier_list";
  }

  @INSAuthority(authorityMenu = MenuEnum.SUPPLIER_LIST)
  @RequestMapping(value = "/supplier/detail", method = RequestMethod.GET)
  public String supplierdetail(
	  @RequestParam(value = "id", required = false, defaultValue = "-1") long supId, Model model) {
	model.addAttribute("typeList", CustTypeEnum.values());
	model.addAttribute("statusList", IsActiveEnum.values());
	if (supId > 0) {
	  model.addAttribute("supplier", supInfoService.findSupById(supId));
	}
	return "supplier/supplier_detail";
  }
}
